//
//  RJCheckDataModel.m
//  AirQuality
//
//  Created by Po on 15/5/4.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJCheckDataModel.h"

@interface RJCheckDataModel ()

@property (assign, nonatomic) BOOL isFree;          //释放
@property (assign)             BOOL status;

@end

@implementation RJCheckDataModel


- (instancetype)initWithStationCode:(NSString *)stationCode freeStatus:(BOOL)status
{
    self = [super init];
//    if (!status) {
//        if (self) {
//            _isFree = NO;
//            _cellKeys = @[@"pm2_5",@"pm10",@"o3",@"so2",@"no2",@"co"];
//            [self getStationDataWithStationCode:stationCode];
//        }
//        return self;
//    }
    if (self) {
        _status =status;
        _isFree = NO;
         _cellKeys = @[@"so2",@"no2",@"co",@"o3",@"pm10",@"pm2_5"];
        [self getStationDataWithStationCode:stationCode];
    }
    return self;
}

- (void)getStationLeftDataWithStationCode:(NSString *)stationCode{
   
    [RJNetWork myNetRequestWithAddress:[NetURL defaultURL].stationData data:@{@"stationcode":stationCode,@"timepoint":[RJTools getTimeWithFormat:@"yyyy-MM-dd" time:YesterdayDate]} completeBlock:^(id responseObject) {
        
        _data = [NSArray arrayWithArray:[responseObject objectForKey:@"data"]];
        
    }failBlack:^(id response) {
        
    }];

}

- (void)getStationDataWithStationCode:(NSString *)stationCode
{
    //http://xsscd.xicp.net:5100/smartadmin/audit/getStationData
    [RJNetWork myNetRequestWithAddress:[NetURL defaultURL].stationData data:@{@"stationcode":stationCode,@"timepoint":[RJTools getTimeWithFormat:@"yyyy-MM-dd" time:YesterdayDate]} completeBlock:^(id responseObject) {
        if (_status) {
            _data = [NSArray arrayWithArray:[responseObject objectForKey:@"data"]];
        }
        if (_isFree) {
            return;
        }
        _data = [NSArray arrayWithArray:[responseObject objectForKey:@"data"]];
        if (_isFree) {
            return;
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:@"didGetData" object:nil];
    }failBlack:^(id response) {
        if (_isFree) {
            return;
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:@"didGetNoData" object:nil userInfo:nil];
    }];
}

- (void)freeAndStop
{
    _isFree = YES;
}
@end
